/**
 * 外部迭代器 next、end
 * 用户需要手动调用next方法, 才能走到下一步
 * express middleware
 */

 namespace Outside {
  export interface IIter {
    arr: number[];
  }
 }

 interface IIterator {
   reduceArr: Outside.IIter['arr'];
   next: () => any;
   end: () => void;
   isDone: boolean;
 }

 class Iterator implements IIterator {
   public reduceArr: Outside.IIter['arr'];
   public isDone = false;
   constructor(props: Outside.IIter) {
     this.reduceArr = props.arr;
   }
   next() {
    this.curIdx++;
    if (this.curIdx >= this.reduceArr.length) {
      this.end();
    }
   }
   getItem() {
     return this.reduceArr[this.curIdx]
   }
   end() {
     this.curIdx = this.reduceArr.length;
     this.isDone = true;
   }
   reset() {
     this.curIdx = 0;
     this.isDone = false;
     this.reduceArr = [];
   }
   private curIdx = 0; // 当前索引
 }

 export default Iterator